package hz.mobileproject.pda.ui.view;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

import hz.mobileproject.pda.R;
import hz.mobileproject.pda.entity.response.Rp_eduType;
import hz.mobileproject.pda.ui.adapter.EduTalkTrackDialogAdapter;

/**
 * Created by Lc on 2017/12/19.
 */

public class EduTalkTrackDialog extends BaseCustomDialog {
    @ViewInject(R.id.lv_checkBox)
    private ListView lv_checkBox;
    @ViewInject(R.id.btn_positive)
    private Button btn_positive;
    @ViewInject(R.id.btn_nagetive)
    private Button btn_nagetive;

    private List<Rp_eduType> mList;
    private EduTalkTrackDialogAdapter mAdapter;
    private OnClickListener onClickListener;

    public EduTalkTrackDialog(Context context,List<Rp_eduType> list) {
        super(context);
        mList = list;
    }

    @Override
    protected int bindView() {
        return R.layout.dialog_edutalk_track;
    }

    @Override
    protected void initData() {
        mAdapter = new EduTalkTrackDialogAdapter(mContext,mList);
        lv_checkBox.setAdapter(mAdapter);
    }

    @Event({R.id.btn_positive,R.id.btn_nagetive})
    private void viewOnClick(View v){
        switch (v.getId()){
            case R.id.btn_positive:
                this.dismiss();
                if(onClickListener != null){
                    List<Rp_eduType> listData = new ArrayList<>();
                    listData.addAll(mAdapter.getListData());
                    for(int i=listData.size()-1;i>=0;i--){
                        if(!listData.get(i).isChecked()){
                            listData.remove(i);
                        }
                    }
                    //返回被选中的列表
                    onClickListener.onPositive(listData);
                }
                break;
            case R.id.btn_nagetive:
                this.dismiss();
                break;
        }
    }

    public EduTalkTrackDialog setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
        return this;
    }

    public interface OnClickListener{
        void onPositive(List<Rp_eduType> listData);
    }
}
